/**
 * $RCSfile$
 * $Revision$
 * $Date$
 * $Source$
 * $Author$
 */
package pl.edu.agh.loganalizator.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;

/**
 * Model regół w systemie
 * @author sadzio
 *
 */
public class RuleModel {
  private LinkedList<Rule> ruleArrayList;
  private HashMap<Rule, Class> availableRuleArrayList;

  public RuleModel() {
    ruleArrayList = new LinkedList<Rule>();
    availableRuleArrayList = new HashMap<Rule, Class>();

    // tu dodajemy zaimplementowane reguly
    availableRuleArrayList.put(new EqualsRule(), EqualsRule.class);
    availableRuleArrayList.put(new NotEqualsRule(), NotEqualsRule.class);
    availableRuleArrayList.put(new MatchesRule(), MatchesRule.class);
    availableRuleArrayList.put(new PairRule(), PairRule.class);
  }

  public ArrayList<Rule> getAvailableRuleCollection() {
    ArrayList<Rule> arrRet = new ArrayList<Rule>();
    for (Entry<Rule, Class> entry : availableRuleArrayList.entrySet()) {
      arrRet.add(entry.getKey());
    }
    return arrRet;
  }

  public Class getRuleCless(Rule rule) {
    return availableRuleArrayList.get(rule);

  }

  public HashMap<Rule, Class> getAvailableRuleArrayList() {
    return availableRuleArrayList;
  }

  public void setRuleArrayList(LinkedList<Rule> ruleArrayList) {
    this.ruleArrayList = ruleArrayList;
  }

  public List<Rule> getRuleArrayList() {
    return ruleArrayList;
  }

  public void addRuleAction(Rule rule) {
    ruleArrayList.add(rule);
  }

  /**
   * sprawdza czy wiersz danych pasuje do wybranych regół
   * @param row
   * @return
   */
  public boolean isParsePositive(Row row) {
    for (Rule rule : ruleArrayList) {
      // stosule logiczny and na regulach
      if (!rule.isParsePositive(row))
        return false;
    }
    return true;
  }

}
